import java.util.Arrays;
import java.util.Scanner;

public class Demo3 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        long total = 0;
        long[] arr = new long[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextLong();
        }
        Arrays.sort(arr);
        long sum = 0;
        for (int i = 0; i < n; i++) {
            long num = arr[i];
            sum = 0;
            for (int j = i + 1; j < n; j++) {
                if (arr[j] == num) {
                    sum += num;
                } else {
                    sum += arr[j] * num;
                }
            }
            total += sum;
            while (i < n - 1 && arr[i + 1] == num) {
                sum -= num;
                total += sum;
                i++;
            }
        }
        System.out.println(total % 1000000007);
    }
}
